package ttsolver.constraints;

import ttsolver.input.Train;

public class ConsPassTrack extends DefaultConstraint {

	private Train train;
	private int milepost;

	public ConsPassTrack() {
		super(ConstraintType.CONS_PASS_TRACK);
	}

	public ConsPassTrack(Train train, int milepost) {
		super(ConstraintType.CONS_PASS_TRACK);
		this.train = train;
		this.milepost = milepost;
	}

	public Train getTrain() {
		return train;
	}

	public void setTrain(Train train) {
		this.train = train;
	}

	public int getMilepost() {
		return milepost;
	}

	public void setMilepost(int milepost) {
		this.milepost = milepost;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((train == null) ? 0 : train.getId().intValue());
		result = prime * result + milepost;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;

		ConsPassTrack other = (ConsPassTrack) obj;

		if (train == null) {
			if (other.train != null)
				return false;
		} else if (!train.equals(other.train)) {
			return false;
		}

		if (milepost != other.milepost) {
			return false;
		}

		return true;
	}

	@Override
	public String toString() {
		String s = "";
		s += (train != null) ? train.getId() : "N/A";
		s += "," + milepost;
		return "Pass_Track_(" + s + "):\n";
	}

}
